package com.lvdp.config;

import com.lvdp.utils.LoginInterceptor;
import com.lvdp.utils.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Description: 配置拦截器的
 * Date:      2022/11/1 21:47
 * author:    LPH
 * version:   V1.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加刷新token拦截器，需要允许所有接口都开放
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);

        // 添加登录拦截器，并且排除以下请求
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
//                        "/shop/**",
//                        "/voucher/**",
//                        "/shop-type/**",
//                        "/upload/**",
//                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ).order(1);

    }
}
